package com.situ.mall.controller.back;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.mall.common.ServerResponse;
import com.situ.mall.entity.User;
import com.situ.mall.service.IUserService;

@RequestMapping("/user")
@Controller
public class UserController {
	@Autowired
	private IUserService userService;

	//跳转到主界面
	@RequestMapping("/getLoginPage")
	public String getLoginPage() {
		return "/user/login";
	}
	
	@RequestMapping("/login")
	@ResponseBody	
	public ServerResponse login(String username, String password, HttpSession session) {
		System.out.println("controller层username = "+username);
		System.out.println("controller层password = "+password);
		ServerResponse response = userService.login(username, password);
		//这个用户是存在的
		if (response.isSuccess()) {
			session.setAttribute("USER", response.getData());
		}
		
		return response;
	}
	
	@RequestMapping("/getUserPage")
	public String getUserPage() {
		return "/user/user_list";
	}
	
	@RequestMapping("/pageList")
	@ResponseBody
	public ServerResponse pageList(Integer page, Integer limit) {
		ServerResponse serverResponse = userService.pageList(page, limit);
		System.out.println(serverResponse);
		return serverResponse;
	}
}
